package com.gp;

import java.util.List;

import com.gp.node.INode;
import com.gp.node.operator.IFather;
import com.stock.StockData;

// this class represent chromosome (since this is GP, the chromosome is tree and therefore implement INode)
// overrides functions description can be found in Inode
public class Chrome implements INode, Comparable<Chrome> {

	private static final long serialVersionUID = 7874881539223383909L;

	// the tree root
	private INode root;
	
	// the chromosome fit and updated fit (the real one)
	private double fit = 0;
	private double updatedFit = 0;

	// c'tor
	public Chrome() {
		root = null;
	}

	@Override
	public double getValue(StockData stock) {
		return root.getValue(stock);
	}

	@Override
	public String print(StockData stock) {
		return root.print(stock);
	}

	// getters and setters:

	public INode getRoot() {
		return root;
	}

	public void setRoot(INode root) {
		this.root = root;
	}


	public double getFit() {
		return fit;
	}

	public void setFit(double fit) {
		this.fit = fit;
	}
	
	public double getUpdatedFit() {
		return updatedFit;
	}
	
	public void setUpdatedFit(double updatedFit) {
		this.updatedFit = updatedFit;
	}

	@Override
	public INode createNew()  {
		return new Chrome();
	}

	@Override
	public String print() {
		return root.print();
	}

	@Override
	public INode copy() {
		Chrome ch= new Chrome();
		ch.root = root.copy();
		return ch;
	}

	@Override
	public void fillAll(List<INode> ls) {
		root.fillAll(ls);
	}

	@Override
	public void fillFathers(List<IFather> ls) {
		root.fillFathers(ls);
	}

	@Override
	public int compareTo(Chrome other) {
		if (this.fit < other.fit) 
			return -1;
		else if (this.fit > other.fit)
			return 1;
		else
			return 0;
	}

	public String toString() {
		//return "(fit:" + fit + ",updatedFit:"+ updatedFit +"," + root.print() +")";
		return "(fit:" + fit + ",updatedFit:"+ updatedFit +")";
	}
}
